home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / frexxed / fpl / macroio.fpl < prev    next >
Text File  |  1995-07-18  |  2KB  |  73 lines

  1.  
  2. export void SaveMacro ()
  3. {
  4.   int id;
  5.   string promptname="";
  6.   string name;
  7.  
  8.   id = PromptBuffer("Macro to save:", 10);
  9.   if (id) {
  10.     promptname="FrexxEd:Macros/"+ReadInfo("full_file_name", id);;
  11.     if (!strlen(ReadInfo("file_path")))
  12.       promptname=joinstr("FrexxEd:Macros/", ReadInfo("file_name", id));
  13.     name=PromptFile(promptname, "Save macro:", "#?.macro");
  14.     if (strlen(name)) {
  15.       int oldid=GetEntryID();
  16.       string insertline;
  17.       string firstline;
  18.       string macrostring;
  19.  
  20.       CurrentBuffer(id);
  21.       firstline=GetLine(1);
  22.  
  23.       if (strncmp(firstline, "/* Macro:", 9))
  24.         insertline=joinstr("/* Macro:", ReadInfo("macro_key"), "*/\n");
  25.  
  26.       CurrentBuffer(oldid);
  27.       macrostring=GetBlock(id);
  28.       if (!GetErrNo()) {
  29.         SaveString(name, joinstr(insertline, macrostring));
  30.       } else
  31.         ReturnStatus("Out of memory!");
  32.     } else
  33.       ReturnStatus("Function cancel!");
  34.   } else
  35.     ReturnStatus("Function cancel!");
  36. }
  37.  
  38.  
  39. export void LoadMacro(string macrofile)
  40. {
  41.  
  42.   string macroname;
  43.  
  44.   if(strlen(macrofile))
  45.     macroname = macrofile;
  46.   else
  47.     macroname=PromptFile("FrexxEd:Macros/", "Load macro:", "#?.macro");
  48.   if (strlen(macroname)) {
  49.     int id;
  50.     int oldid=GetEntryID();
  51.     id=New();
  52.     if (id) {
  53.       string firstline;
  54.       CurrentBuffer(id);
  55.       if (Load(macroname)>=0) {
  56.         firstline=GetLine(1);
  57.         if (!strncmp(firstline, "/* Macro:", 9)) {
  58.           int len;
  59.           len=strstr(firstline, "*/\n");
  60.           if (len)
  61.             AssignKey(joinstr("ExecuteBuffer(", ltostr(id), ");"), substr(firstline, 9, len-9));
  62.           SetInfo(id, "macro_key", substr(firstline, 9, len-9));
  63.           SetInfo(id, "type", 10);
  64.         } else {
  65.           ReturnStatus("No macro!");
  66.           Kill(id);
  67.         }
  68.       }
  69.       CurrentBuffer(oldid);
  70.     }
  71.   }
  72. }
  73.